<template>
  <div class="jump-type">
    <el-table v-loading="loading" border :data="tableData" row-key="id">
      <el-table-column prop="id" fixed="left" width="180" label="商品编号" align="center"></el-table-column>
      <el-table-column prop="name" label="商品名称" :show-overflow-tooltip="true" align="center"></el-table-column>
      <el-table-column label="商品图片" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <template v-if="scope.row.fileList.length > 0">
            <el-image style="height: 60px; border-radius: 5px;" :src="scope.row.fileList[0].fileUrl"
              :preview-src-list="getPreviewList(scope.row.fileList)"></el-image>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="price" label="到手价（¥）" :show-overflow-tooltip="true" align="center"></el-table-column>
      <el-table-column prop="brokerageRatio" label="佣金比（%）" align="center"></el-table-column>
      <el-table-column prop="brokerage" label="佣金（¥）" align="center"></el-table-column>
      <el-table-column prop="readCount" label="浏览量" align="center"></el-table-column>
      <el-table-column prop="clickCount" label="点击量" align="center"></el-table-column>
      <el-table-column prop="shopName" label="所属门店" align="center"></el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-check" @click="selectRow(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="box-center">
      <el-pagination @current-change="handleCurrentChange" :current-page.sync="params.pageNum"
        layout="prev, pager, next" :page-size="params.pageSize" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { goodsList } from '@/api/tktk/goods'
export default {
  name: "SelectGoods",
  data() {
    return {
      tableData: [],
      total: 0,
      loading: false,
      params: {
        feature: -1,
        pageNum: 1,
        pageSize: 10,
      }
    }
  },

  methods: {
    selectRow(row) {
      const { id, name } = row
      console.log('1123')
      this.$emit('transfer', { id, name })
    },
    getPreviewList(fileList) {
      let list = []
      fileList.map(item => {
        list.push(item.fileUrl)
      })
      return list
    },

    getGoodsList() {
      this.loading = true
      goodsList(this.params).then(res => {
        if (res.code === 200) {
          this.tableData = res.rows || []
          this.total = res.total || 0
          this.loading = false
        }
      })
    },

    handleCurrentChange(page) {
      this.params.pageNum = page
      this.getGoodsList()
    }
  },

  mounted() {
    this.getGoodsList()
  }
}
</script>

<style lang="scss" scoped>
.jump-type {
  width: 100%;
  padding: 20px;
}
</style>
